home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / publish / PublishServer.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  15.2 KB  |  528 lines

  1. /****i* SOURCE_FILE/INFO
  2. *
  3. * NAME
  4. *    PublishServer.js
  5. *
  6. * USAGE
  7. *    Part of WPS JavaScript Library.
  8. *
  9. * COPYRIGHT
  10. *    Copyright ⌐ 2000-2001 Website Pros, Inc.
  11. *    All Rights Reserved.
  12. *
  13. *  This is an unpublished work protected by Website Pros, Inc.
  14. *  as a trade secret, and is not to be used or disclosed except as
  15. *  expressly provided in a written license agreement executed by
  16. *  you and Website Pros, Inc.
  17. *
  18. *      <copyright@websitepros.com>
  19. *
  20. * NOTES
  21. *    JavaScript code.
  22. *
  23. *****/
  24. if (!IS.isModuleInitialized("IS.NOF.PUBLISH.PublishServer"))
  25.     /** 
  26.     * Class PublishServer
  27.     *
  28.     * External dependencies: NOF.XML.XmlDocument, NOF.UTIL.ResourceBundle, NOF.UTIL.DefaultLocale
  29.     **/
  30.     function NOF_PublishServer(/*PublishServer*/ pServer) {
  31.         this.__proto__ = NOF_PublishServer.prototype;  
  32.  
  33.         if (typeof(pServer) != 'string') {
  34.             this.pPublishServer = pServer;
  35.             this.global = false;
  36.         } else {
  37.             //NOF.util_logging_ConsoleLogger_global.info("PublishSeerver.GlobalInit : " + pServer);
  38.             this.publishProfile = new NOF.PUBLISHSETTINGS.PublishConfigFile(pServer);
  39.             this.publishProfile.loadConfigFile();
  40.             //this.publishProfile.setName(pServer);
  41.             this.global = true;
  42.             //NOF.util_logging_ConsoleLogger_global.info("PublishSeerver.GlobalInit : " + this.getName());
  43.         }
  44.  
  45.           this.xmlAdvProp = NOF.XML.XmlDocument.create(); 
  46.           this.xmlAdvProp.loadXML( this.getAdvancedSettings() );
  47.  
  48.         this.typeLabel = null;
  49.     }
  50.     {      
  51.         var members = NOF_PublishServer.prototype;
  52.         members.CLASS_NAME = "PublishServer";
  53.         
  54.         members.ADVANCED_SETTINGS = "advancedsettings";
  55.         members.VIRTUAL_FOLDERS = "virtualFolders";
  56.  
  57.         // Flag to show if server settings have been modified
  58.         members.isModified = false;
  59.         
  60.         var methods = NOF_PublishServer.prototype;
  61.  
  62.         /**
  63.         * Name of the published home page.
  64.         **/
  65.         methods.getHomePageName = function () {
  66.             if (this.isGlobal())
  67.                 return this.publishProfile.getHomePageName();
  68.             else
  69.                 return this.pPublishServer.HomePageName;
  70.         }
  71.         methods.setHomePageName = function (/*int*/ pageID) {
  72.             if (this.isGlobal()) {
  73.                 this.publishProfile.setHomePageName(pageID);
  74.                 this.publishProfile.saveConfigFile();
  75.             } else {
  76.                 this.pPublishServer.HomePageName = pageID;
  77.             }
  78.         }
  79.  
  80.         /**
  81.         * Default HTML file extension.
  82.         **/
  83.         methods.getHTMLFileExtension = function () {
  84.             if (this.isGlobal())
  85.                 return this.publishProfile.getFileExtension();
  86.             else
  87.                 return this.pPublishServer.HTMLFileExt;
  88.         }
  89.         /**
  90.         * Default HTML file extension.
  91.         **/
  92.         methods.setHTMLFileExtension = function (extension) {
  93.             if (this.isGlobal()) {
  94.                 this.publishProfile.setFileExtension(extension);
  95.                 this.publishProfile.saveConfigFile();
  96.             } else {
  97.                 this.pPublishServer.HTMLFileExt = extension;
  98.             }
  99.         }
  100.         
  101.         /**
  102.         *  Name of the publish server, is unique within a site.
  103.         **/
  104.         methods.getName = function () {
  105.             if (this.isGlobal())
  106.                 return this.publishProfile.getName();
  107.             else
  108.                 return this.pPublishServer.Name;
  109.         }
  110.         /**
  111.         *  Name of the publish server, is unique within a site.
  112.         **/
  113.         methods.setName = function (name) {
  114.             if (this.isGlobal()) {
  115.                 this.publishProfile.setName(name);
  116.                 this.publishProfile.saveConfigFile();
  117.             } else {
  118.                 this.pPublishServer.SetName(name);
  119.             }
  120.         }
  121.         
  122.         /**
  123.         * URL of publish server
  124.         **/
  125.         methods.getURL = function () {
  126.             if (this.isGlobal())
  127.                 return this.publishProfile.getURL();
  128.             else
  129.                 return this.pPublishServer.URL;
  130.         }
  131.         /**
  132.         * URL of publish server
  133.         **/
  134.         methods.setURL = function (url) {
  135.             if (this.isGlobal()) {
  136.                 this.publishProfile.setURL(url);
  137.                 this.publishProfile.saveConfigFile();
  138.             } else {
  139.                 this.pPublishServer.URL = url;
  140.             }
  141.         }
  142.  
  143.         /**
  144.         * type of server (protocol): local, ftp, webdav, etc
  145.         **/
  146.         methods.getType = function () {
  147.             if (this.isGlobal())
  148.                 return this.publishProfile.getType();
  149.             else
  150.                 return this.pPublishServer.ServerType;
  151.         }
  152.         /**
  153.         * type of server (protocol): local, ftp, webdav, etc
  154.         **/
  155.         methods.setType = function (type) {
  156.             var oldType = this.getType();
  157.             if (type != oldType) {                
  158.                 if (this.isGlobal()) {
  159.                     this.publishProfile.setType(type);
  160.                     this.publishProfile.saveConfigFile();
  161.                 } else {
  162.                     this.pPublishServer.ServerType = type;
  163.                 }
  164.  
  165.                 this.typeLabel = null;
  166.             }
  167.         }
  168.         
  169.         methods.getTypeLabel = function () {
  170.             if (this.typeLabel == null) {
  171.                 var type = this.getType();
  172.                 var rs = NOF.UTIL.ResourceBundle.getBundle("PublishSettings/" + type + "/" + type, NOF.UTIL.DefaultLocale);
  173.                 this.typeLabel = rs.getProperty("publishServer.type.Label");
  174.             }
  175.             return this.typeLabel;
  176.         }
  177.         
  178.         methods.isGlobal = function () {
  179.             return this.global;
  180.         }
  181.         
  182.         /**
  183.         * @return true if the profile is a local profile and 
  184.         * it has an associated global profile 
  185.         **/
  186.         methods.hasGlobalProfile = function () {
  187.             if (this.isGlobal()) return false;
  188.             return this.pPublishServer.HasGlobalProfile();
  189.         }
  190.         
  191.         /**
  192.         * @return true if the profile is a local profile and 
  193.         * it has a newer global profile associated.
  194.         **/
  195.         methods.isGlobalNewer = function () {
  196.             if (this.isGlobal()) return false; //! throw new NOF.UTIL.Exception();
  197.             return this.pPublishServer.IsGlobalNewer();
  198.         }
  199.         
  200.         /**
  201.         * @return the name of the global profile associated if the profile is a local profile,
  202.         * or null if it is a global profile.
  203.         **/
  204.         methods.getGlobalFileName = function () {
  205.             if (this.isGlobal()) return null; //throw new NOF.UTIL.Exception();
  206.             return this.pPublishServer.GlobalFileName;
  207.         }
  208.         
  209.  
  210.         methods.test = function () {
  211.             if (!this.isGlobal()) {
  212.                 //NOF.util_logging_ConsoleLogger_global.info("PublishServer.Test - Global isRemote: ");// + this.pPublishServer.SaveGlobal("GlProf" + this.getName()));
  213.                 //return this.pPublishServer.SaveGlobal("GlProf" + this.getName());
  214.                 var testResult = this.pPublishServer.Test();
  215.                 log.info(" testResult = " + testResult, "PublishServer", "test");
  216.                 return testResult;
  217.             } else 
  218.                 return false;
  219.         }                
  220.         
  221.         /**
  222.         * True if this is a local publish server, false if remote server.
  223.         **/
  224.         methods.isLocalType = function () {
  225.             if (this.isGlobal())
  226.                 return ((this.publishProfile.getType() == 'local') ? true : false);
  227.             else
  228.                 return (this.pPublishServer.UseLocal);
  229.         }
  230.         
  231.         /**
  232.         *  base directory on remote server (null for local)
  233.         **/
  234.         methods.getBaseDirectory = function () {
  235.             if (this.isGlobal())
  236.                 return this.publishProfile.getBaseDirectory();
  237.             else
  238.                 return this.pPublishServer.BaseDirectory;
  239.         }
  240.         /**
  241.         *  base directory on remote server (null for local)
  242.         **/
  243.         methods.setBaseDirectory = function (directory) {
  244.             if (this.isGlobal()) {
  245.                 this.publishProfile.setBaseDirectory(directory);
  246.                 this.publishProfile.saveConfigFile();
  247.             } else {
  248.                 this.pPublishServer.BaseDirectory = directory;
  249.             }
  250.         }    
  251.         
  252.         /**
  253.         *  UserName: user name for connection to remote server (null for local)
  254.         **/
  255.         methods.getUserName = function () {
  256.             if (this.isGlobal())
  257.                 return this.publishProfile.getUserName();
  258.             else
  259.                 return this.pPublishServer.UserName;
  260.         }    
  261.         /**
  262.         *  UserName: user name for connection to remote server (null for local)
  263.         **/
  264.         methods.setUserName = function (name) {
  265.             if (this.isGlobal()) {
  266.                 this.publishProfile.setUserName(name);
  267.                 this.publishProfile.saveConfigFile();
  268.             } else {
  269.                 this.pPublishServer.UserName = name;
  270.             }
  271.         }    
  272.         
  273.         /**
  274.         *  Password for connection to remote server.
  275.         **/
  276.         methods.getPassword = function () {
  277.             //throw new NOF.UTIL.Exception("invalid method call");
  278.             //return '********';
  279.             if (this.isGlobal())
  280.                 return this.publishProfile.getPassword();
  281.             else
  282.                 return this.pPublishServer.Password;
  283.         }    
  284.         /**
  285.         *  Password for connection to remote server.
  286.         **/
  287.         methods.setPassword = function (pswd) {
  288.             if (this.isGlobal()) {
  289.                 this.publishProfile.setPassword(pswd);
  290.                 this.publishProfile.saveConfigFile();
  291.             } else {
  292.                 this.pPublishServer.Password = pswd;
  293.             }
  294.         }    
  295.         
  296.         /**
  297.         * Advanced Settings of publish server
  298.         **/
  299.         methods.getAdvancedSettings = function () {
  300.             if (this.isGlobal()) {
  301.                 var sStr = this.publishProfile.getAdvancedSettings();
  302.                 if (sStr == null) sStr = "";
  303.                 sStr = "<" + this.ADVANCED_SETTINGS + ">" + sStr + 
  304.                         "</" + this.ADVANCED_SETTINGS + ">";
  305.                 
  306.                 //NOF.util_logging_ConsoleLogger_global.info("PublishServer.GetAdvSet : " + sStr);
  307.                 return new NOF.PUBLISH.AdvancedSettings(sStr);
  308.             } else {
  309.                 if ((this.pPublishServer.AdvancedSettings == null) ||
  310.                     ("" == this.pPublishServer.AdvancedSettings)) {
  311.                     this.pPublishServer.AdvancedSettings = "<" 
  312.                         + this.ADVANCED_SETTINGS + ">" +
  313.                         "</" + this.ADVANCED_SETTINGS + ">";
  314.                 }
  315.                 
  316.                 return new NOF.PUBLISH.AdvancedSettings(this.pPublishServer.AdvancedSettings);
  317.             }
  318.         }
  319.         /**
  320.         * Advanced Settings of publish server
  321.         **/
  322.         methods.setAdvancedSettings = function (/*AdvancedSettings*/ advancedSettings) {
  323.             var advSetStr = advancedSettings.toXML();
  324.             if (this.isGlobal()) {
  325.                 //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 1: " + advSetStr);
  326.                 if ((advSetStr != null) && ("" != advSetStr)) {
  327.                     var sStr = "<" + this.ADVANCED_SETTINGS + ">";
  328.                     var idx = advSetStr.indexOf(sStr);
  329.                     if (idx >= 0) {
  330.                         advSetStr = advSetStr.substring(idx + sStr.length, advSetStr.length);
  331.                     }
  332.  
  333.                     sStr = "</" + this.ADVANCED_SETTINGS + ">";
  334.                     idx = advSetStr.indexOf(sStr);
  335.                     if (idx >= 0) {
  336.                         advSetStr = advSetStr.substring(0, idx);
  337.                     }
  338.                     //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 2: " + advSetStr);
  339.                 }
  340.  
  341.                 this.publishProfile.setAdvancedSettings(advSetStr);
  342.                 //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 3");
  343.                 
  344.                 this.publishProfile.saveConfigFile();
  345.                 //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 4");
  346.             } else {
  347.                 var sStr = "<" + this.ADVANCED_SETTINGS + ">";
  348.                 if (advSetStr.indexOf(sStr) < 0) {
  349.                     advSetStr = "<" + this.ADVANCED_SETTINGS + ">" 
  350.                             + advSetStr + "</" + this.ADVANCED_SETTINGS + ">";
  351.                 }
  352.                 this.pPublishServer.AdvancedSettings = advSetStr;
  353.             }
  354.             
  355.             this.xmlAdvProp.loadXML( this.getAdvancedSettings().toXML() );
  356.         }
  357.  
  358.         /**
  359.         * get Virtual Folders of publish server
  360.         **/
  361.         methods.getAliases = function () {
  362.             if (this.isGlobal()) {
  363.                 this.xmlAdvProp.loadXML( this.getAdvancedSettings().toXML() );
  364.                 var node = this.xmlAdvProp.documentElement.selectSingleNode("//virtualFolders");
  365.  
  366.                 var sStr = null;
  367.                 if (node != null) sStr = node.xml;
  368.                 if (sStr == null) sStr = "";
  369.                 if ("" == sStr) {
  370.                     sStr = "<" + this.VIRTUAL_FOLDERS + ">" + sStr + 
  371.                             "</" + this.VIRTUAL_FOLDERS + ">";
  372.                 }
  373.                 //NOF.util_logging_ConsoleLogger_global.info("Get PublishSettingsAliases: " + sStr);
  374.                 
  375.                 return new NOF.PUBLISH.Aliases(sStr);
  376.             } else {
  377.                 var sStr = "<" + this.VIRTUAL_FOLDERS + "></" + this.VIRTUAL_FOLDERS + ">";
  378.                 var xmlAliases = NOF.XML.XmlDocument.create(); 
  379.                 xmlAliases.loadXML( sStr );
  380.                 var node = xmlAliases.documentElement.selectSingleNode("/" + this.VIRTUAL_FOLDERS);
  381.                 
  382.                 var aliasIter = this.pPublishServer.GetVirtualFolders();
  383.  
  384.                 var aliaslength = aliasIter.Count();
  385.                 for (i = 0; i < aliaslength; i++)
  386.                 {
  387.                     var alias = aliasIter.GetNext();
  388.                     if (alias)
  389.                     {
  390.                         var newVirFold = this.xmlAdvProp.createElement("virtualFolder");
  391.                         var newURL = this.xmlAdvProp.createElement("urlPath");
  392.                         var newPATH = this.xmlAdvProp.createElement("ftpPath");
  393.                         newURL.appendChild(this.xmlAdvProp.createTextNode(alias.URLPath));
  394.                         newPATH.appendChild(this.xmlAdvProp.createTextNode(alias.FTPPath));
  395.                         newVirFold.appendChild(newURL);
  396.                         newVirFold.appendChild(newPATH);
  397.                         node.appendChild(newVirFold);
  398.                     }
  399.                 }
  400.                 
  401.                 return new NOF.PUBLISH.Aliases(xmlAliases.xml);
  402.             }
  403.         }
  404.  
  405.         /**
  406.         * set Virtual Folders of publish server
  407.         **/
  408.         methods.setAliases = function (/*Aliases*/ aliases) {
  409.             if (this.isGlobal()) {
  410.                 var xmlAliases = NOF.XML.XmlDocument.create(); 
  411.                 xmlAliases.loadXML( aliases.toXML() );
  412.                 this.xmlAdvProp.loadXML( this.getAdvancedSettings().toXML() );
  413.  
  414.                 var node = this.xmlAdvProp.documentElement.selectSingleNode("//virtualFolders");
  415.                 var nodeVar = xmlAliases.documentElement.selectSingleNode("/virtualFolders");
  416.                 if (node == null) {
  417.                     //NOF.util_logging_ConsoleLogger_global.info("Save aliases: as child");
  418.                     this.xmlAdvProp.documentElement.appendChild(nodeVar);
  419.                 } else {
  420.                     //NOF.util_logging_ConsoleLogger_global.info("Save aliases: as node");
  421.                     var parNode = node.parentNode;
  422.                     parNode.removeChild(node);
  423.                     this.xmlAdvProp.documentElement.appendChild(nodeVar);
  424.                     //NOF.util_logging_ConsoleLogger_global.info("Save aliases: as node - done");
  425.                     //node = nodeVar;
  426.                 }
  427.                 var advSet = new NOF.PUBLISH.AdvancedSettings(this.xmlAdvProp.xml);
  428.                 //advSet.setProperty("virtualFolders", nodeVar.xml);
  429.                 
  430.                 //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 5");
  431.                 this.setAdvancedSettings(advSet);
  432.                 //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 6");
  433.             } else {
  434.                 var aliasIter = aliases.iterator();
  435.                 for (; aliasIter.hasNext();) 
  436.                 {
  437.                     var alias = aliasIter.next();
  438.  
  439.                     var origAliasIter = this.pPublishServer.GetVirtualFolders();
  440.  
  441.                     var aliaslength = origAliasIter.Count();
  442.                     var exists = false;
  443.                     for (i = 0; i < aliaslength; i++)
  444.                     {
  445.                         var aliasOrig = origAliasIter.GetNext();
  446.                         if (aliasOrig)
  447.                         {
  448.                             if (aliasOrig.URLPath == alias.getURL()) { 
  449.                                 //modify
  450.                                 exists = true;
  451.                                 aliasOrig.URLPath = alias.getURL();
  452.                                 aliasOrig.FTPPath = alias.getPath();
  453.                             }
  454.                         }
  455.                     }
  456.                     if (!exists) {
  457.                         //add
  458.                         this.pPublishServer.NewVirtualFolder(alias.getURL(), alias.getPath());
  459.                     }
  460.                 }
  461.                 
  462.                 var origAliasIter = this.pPublishServer.GetVirtualFolders();
  463.  
  464.                 var aliaslength = origAliasIter.Count();
  465.                 for (i = 0; i < aliaslength; i++)
  466.                 {
  467.                     var aliasOrig = origAliasIter.GetNext();
  468.                     if (aliasOrig)
  469.                     {
  470.                         var exists = false;
  471.                         
  472.                         var aliasesIter = aliases.iterator();
  473.                         for (; aliasesIter.hasNext();)
  474.                         {
  475.                             var alias = aliasesIter.next();
  476.                             if (aliasOrig.URLPath == alias.getURL()) { 
  477.                                 //modify
  478.                                 exists = true;
  479.                             }
  480.                         }
  481.                         
  482.                         if (!exists) {
  483.                             //delete
  484.                             aliasOrig.Remove();
  485.                         }
  486.                     }
  487.                 }
  488.             }
  489.         }
  490.  
  491.         /**
  492.         * 
  493.         **/
  494.         methods.setProperty = function (propName, propValue) {
  495.             eval("this.set" + propName + "(propValue)");
  496.         }
  497.         /**
  498.         * 
  499.         **/
  500.         methods.getProperty = function (propName) {
  501.             var propValue = eval("this.get" + propName + "()");
  502.             return propValue;
  503.         }
  504.  
  505.         /**
  506.         *  Remove current server.
  507.         **/
  508.         methods.remove = function () {
  509.             if (this.isGlobal())
  510.                 this.publishProfile.deleteConfigFile();
  511.             else
  512.                 this.pPublishServer.Remove();
  513.         }    
  514.  
  515.         /**
  516.         *  Get current server.
  517.         **/
  518.         methods.getPublishServer = function () {
  519.             if (this.isGlobal())
  520.                 return this.publishProfile;
  521.             else
  522.                 return this.pPublishServer;
  523.         }        
  524.     }    
  525.  
  526.     NOF.PUBLISH.__proto__.PublishServer = NOF_PublishServer;
  527. }